package com.loongtech.bi.manager.game;

import com.loongtech.bi.entity.game.EntityActiveRole1LevelDistribute;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 角色的日流失
 * @author lihui
 *
 */
@Service
public class ActiveRole1LevelDistributeManager extends ManagerQueryCacheBase<EntityActiveRole1LevelDistribute> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 * @param dayDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @return
	 */
	public List<Object[]> getAllKindRoleNumberGroupByLevel(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select level,sum(role_number) from EntityActiveRole1LevelDistribute where day =:dayDate and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level order by sum(role_number) desc", "dayDate", dayDate);
	}
	
	/**
	 * 
	 * @param dayDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @return
	 */
	public List<Object[]> getAllKindRoleNumber(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select sum(role_number),count(role_number) from EntityActiveRole1LevelDistribute where day =:dayDate and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"'", "dayDate", dayDate);
	}
	
	/**
	 * 
	 * @param startDate
	 * @param endDate
	 * @param queryPlatform
	 * @param queryChannel
	 * @param queryServer
	 * @param minLevel
	 * @return
	 */
	public List<Object[]> getAllKindRoleNumberGroupByLevel(Date startDate, Date endDate, String queryPlatform, String queryChannel, String queryServer, int minLevel) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),level,role_number from EntityActiveRole1LevelDistribute where day>=:startDate and day<=:endDate and platformid=:queryPlatform and channelid=:queryChannel and serverid=:queryServer and level >= :minLevel ",
				"startDate", startDate,
				"endDate", endDate,
				"queryPlatform", queryPlatform,
				"queryChannel", queryChannel,
				"queryServer", queryServer,
				"minLevel", minLevel);
	}
}
